﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/1/2009
 * Time: 9:35 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of OpenWindowListPane.
	/// </summary>
	public partial class OpenWindowListPane : UserControl
	{
		IList<Form> forms = new List<Form>();
		
		public OpenWindowListPane()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
		}
		
		public void AddForm(Form form)
		{
			forms.Add(form);
			form.Closed += delegate { RemoveForm(form); };
			RefreshList();
		}
		
		public void RemoveForm(Form form)
		{
			forms.Remove(form);
			RefreshList();
		}
		
		void RefreshList()
		{
			listBox1.Items.Clear();
			foreach (Form form in forms) {
				listBox1.Items.Add(form.Text);
			}
			if (forms.Count > 12) {
				listBox1.Height = 160 + ((forms.Count - 12) * 13);
			} else {
				listBox1.Height = 160;
			}
		}
		
		void ListBox1SelectedIndexChanged(object sender, EventArgs e)
		{
			if (listBox1.SelectedIndex >= 0) {
				forms[listBox1.SelectedIndex].Activate();
			}
		}
	}
}
